package edu.chl.grupp11.aegas.view;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

import javax.swing.JComboBox;

import edu.chl.grupp11.aegas.model.AbstractMetaTag;

public class DropdownTagView extends TagView {
	private static final long serialVersionUID = 1L;
	private JComboBox dropdown;
	ArrayList<String> genreList;

	public DropdownTagView(AbstractMetaTag tag) throws FileNotFoundException {
		super(tag);

		remove(valueTextField);

		File genres = new File("src/Genres.txt");
		Scanner sc;
		sc = new Scanner(genres);
		ArrayList<String> genreList = new ArrayList<String>();
		while (sc.hasNextLine()) {
			genreList.add(sc.nextLine());
		}

		dropdown = new JComboBox(genreList.toArray());
		int value = Integer.parseInt(super.getValue());
		dropdown.setSelectedIndex(value);
		dropdown.addFocusListener(this);
		add(dropdown);
	}

	@Override
	public String getValue() {
		if (dropdown.getSelectedIndex() == 126) {
			return "[different values]";
		} else {
			return dropdown.getSelectedIndex() + "";
		}
	}

	public void setValue(String value) {
		if (value.equals("[different values]")) {
			dropdown.setSelectedIndex(126);
		}
	}
}
